﻿namespace tron_range
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int year = 2018;
            int month = 10;
            while (true)
            {
                DateTime time = new DateTime(year, month, 1, 0, 0, 0, DateTimeKind.Local);


                month++;
                if (month > 12)
                {
                    month = 1;
                    year++;
                }
                DateTime time2 = new DateTime(year, month, 1, 0, 0, 0, DateTimeKind.Local);
                if (time2 > DateTime.Now) break;

                Console.WriteLine("range=" + time + " ---" + time2);
                CreateAndSetRange(time, time2);


            }

        }
        static void CreateAndSetRange(DateTime time, DateTime time2)
        {
            var srcpath = "srcfile";
            var files = System.IO.Directory.GetFiles(srcpath);
            var destpath = "range_" + time.Year.ToString("D04") + "_" + time.Month.ToString("D02");

            if (System.IO.Directory.Exists(destpath) == false)
            {
                System.IO.Directory.CreateDirectory(destpath);
            }
            foreach (var f in files)
            {
                var destf = System.IO.Path.Combine(destpath, System.IO.Path.GetFileName(f));
                System.IO.File.Copy(f, destf,true);
                var range0 = new DateTimeOffset(time).ToUnixTimeMilliseconds();
                var range1 = new DateTimeOffset(time2).ToUnixTimeMilliseconds();
                System.IO.File.WriteAllLines(System.IO.Path.Combine(destpath, "range.txt"), new string[] { range0.ToString(), range1.ToString() });
            }
        }
    }
}